/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.handler.generator.impl;

import com.jzz.crawlerweb.handler.generator.ImageHandler;

import java.awt.*;
import java.awt.image.BufferedImage;

public class DefaultBackgroundImageHandler implements ImageHandler {
    private final Color start = new Color(78, 78, 78);
    private final Color end = new Color(151, 151, 151);

    @Override
    public BufferedImage handle(BufferedImage bi, Object... args) {
        BufferedImage bgImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bgImg.createGraphics();

        GradientPaint paint = new GradientPaint(0, 0, start, bi.getWidth(), bi.getHeight(), end);
        g2d.setPaint(paint);
        g2d.fillRect(0, 0, bi.getWidth(), bi.getHeight());
        g2d.drawImage(bi, 0, 0, null);
        return bgImg;
    }
}
